<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="班级名称" prop="coursename">
        <el-input
          v-model="queryParams.coursename"
          placeholder="例：2024春季硬笔书法"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学员名称" prop="cuser">
        <el-input
          v-model="queryParams.cuser"
          placeholder="例：陈文耀"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="16+1补" prop="beizhu">
        <el-input
          v-model="queryParams.beizhu"
          placeholder="请输入16+1补"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="2024.03.02" prop="signdate">
        <el-input
          v-model="queryParams.signdate"
          placeholder="请输入2024.03.02"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="0 未签到  1签到" prop="issigned">
        <el-input
          v-model="queryParams.issigned"
          placeholder="请输入0 未签到  1签到"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1+1补 单个没签到备注" prop="signtext">
        <el-input
          v-model="queryParams.signtext"
          placeholder="请输入1+1补 单个没签到备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="积分" prop="jifen">
        <el-input
          v-model="queryParams.jifen"
          placeholder="请输入积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="老师签名" prop="teachername">
        <el-input
          v-model="queryParams.teachername"
          placeholder="请输入老师签名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="createtime">
        <el-date-picker clearable
          v-model="queryParams.createtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:clocking:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:clocking:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:clocking:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:clocking:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="clockingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="50" label="ID" align="center" prop="id" />
      <el-table-column label="课程名称" align="center" prop="coursename" />
      <el-table-column label="学员姓名" align="center" prop="cuser" />
      <el-table-column label="备注(16+1补)" align="center" prop="beizhu" />
      <el-table-column label="签到日期" align="center" prop="signdate" />
      <el-table-column width="170" label="签到（0未签 1已签到）" align="center" prop="issigned" />
      <el-table-column width="170" label=" 单补签说明（1+1补）" align="center" prop="signtext" />
      <el-table-column label="积分" align="center" prop="jifen" />
      <el-table-column label="老师签名" align="center" prop="teachername" />
      <el-table-column label="创建时间" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:clocking:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:clocking:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog ref="dialog" :title="title" :visible.sync="open" width="500px" :close-on-click-modal="false">
      <template #title>
        <!--  @click.stop.prevent="getMouseEvent($event)" -->
        <!--  @mousedown.stop.prevent="startDrag($refs.dialog)" -->
        <div class="dialog-title" @mousedown.stop.prevent="getMouseEvent($event)">
          鼠标移动区域
        </div>
    </template>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="课程名称" prop="coursename">
                  <el-input v-model="form.coursename" placeholder="例：2024春季硬笔书法终极版(周六14:30-16:00)" />
                </el-form-item>
                <el-form-item label="学员姓名" prop="cuser">
                  <el-input v-model="form.cuser" placeholder="例：陈文耀" />
                </el-form-item>
                <el-form-item label="备注(16+1补)" prop="beizhu">
                  <el-input v-model="form.beizhu" placeholder="例：16+1补" />
                </el-form-item>
                <el-form-item label="签到日期" prop="signdate">
                  <!-- <el-input v-model="form.signdate" placeholder="例: 2024.03.02" /> -->
                  <el-date-picker clearable
                    v-model="form.signdate"
                    type="date"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd"
                    placeholder="例: 2024.03.02"
                    @change="signDate">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="签到" prop="issigned">
                  <el-input v-model="form.issigned" placeholder="0 未签到  1已签到" />
                </el-form-item>
                <el-form-item label="单签备注" prop="signtext">
                  <el-input v-model="form.signtext" placeholder="例：1+1补" />
                </el-form-item>
                <el-form-item label="积分" prop="jifen">
                  <el-input v-model="form.jifen" placeholder="请输入积分" />
                </el-form-item>
                <el-form-item label="老师签名" prop="teachername">
                  <el-input v-model="form.teachername" placeholder="请输入老师签名" />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
              </div>
    </el-dialog>
  </div>
</template>

<script>
import { listClocking, getClocking, delClocking, addClocking, updateClocking } from "@/api/system/clocking";
import { DraggableModal } from '@/utils/draggable-modal';
export default {
  name: "Clocking",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      clockingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        coursename: null,
        cuser: null,
        beizhu: null,
        signdate: null,
        issigned: null,
        signtext: null,
        jifen: null,
        teachername: null,
        createtime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        coursename: [
          { required: true, message: "课程名称不能为空", trigger: "blur" }
        ],
        cuser: [
          { required: true, message: "学员姓名不能为空", trigger: "blur" }
        ],
      },
      movseEvent:null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getMouseEvent(event){
      console.log("获取鼠标事件:",event);
      this.startDrag(this.$refs.dialog,event);
    },
    startDrag(dialog,event){
        DraggableModal.startDrag(dialog,event);
    },
    signDate(){
        
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listClocking(this.queryParams).then(response => {
        this.clockingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        coursename: null,
        cuser: null,
        beizhu: null,
        signdate: null,
        issigned: null,
        signtext: null,
        jifen: null,
        teachername: null,
        createtime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【签到积分】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getClocking(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【签到积分】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClocking(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addClocking(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delClocking(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/clocking/export', {
        ...this.queryParams
      }, `clocking_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.dialog-footer,
.dialog-title {
  cursor: move; /* 更现实地显示可拖拽区域 */
  /* 其他样式 */
}
</style>